﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using WebApi_ProductText1.Domain;
using WebApi_ProductText1.Domain.Entity;

namespace WebApi_ProductText1.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class WeatherForecastController : ControllerBase
    {
        private static readonly string[] Summaries = new[]
        {
            "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
        };

        private readonly ILogger<WeatherForecastController> _logger;

        public WeatherForecastController(ILogger<WeatherForecastController> logger)
        {
            _logger = logger;
        }

        //[HttpGet]
        //public IEnumerable<WeatherForecast> Get()
        //{
        //    var rng = new Random();
        //    return Enumerable.Range(1, 5).Select(index => new WeatherForecast
        //    {
        //        Date = DateTime.Now.AddDays(index),
        //        TemperatureC = rng.Next(-20, 55),
        //        Summary = Summaries[rng.Next(Summaries.Length)]
        //    })
        //    .ToArray();
        //}
        [HttpGet]
        public string Get()
        {
            ////  JsonSerializerSettings:Json序列化器设置
            //JsonSerializerSettings settings =new JsonSerializerSettings();
            //// ContractResolver:合同分解器  CamelCasePropertyNamesContractResolver:驼峰大小写属性名称解析器
            //settings.ContractResolver = new CamelCasePropertyNamesContractResolver();

            var list = new List<User>();
            var db = new Sell10000Context();
            
                list = db.Users.ToList();


            // Formatting:格式化  Indented:缩进排印的
            // settings.Formatting = Formatting.Indented;
            
            // JsonConvert:Json转换 ,SerializeObject:序列化对象
            string str = JsonConvert.SerializeObject(list, Formatting.Indented)+ JsonConvert.SerializeObject(db.Products.ToList<Product>(), Formatting.Indented);
            return str ;
        }

       
    }
}
